package trystero.lib.http;

import java.net.URLEncoder;
import java.util.Vector;

public class POSTData
{
   Vector keys;
   Vector values;
   String data;

   public POSTData() 
   {
     this.keys = new Vector();
     this.values = new Vector();
   }

   public Vector keys() { return this.keys; }
   public Vector values() { return this.values; }

   public void add(String key, String value) 
   {
      keys.add(key); 
      values.add(value);
   }

   public String toString()
   {
      //if(keys.size() != values.size())
      //   throw new Exception("Keys/values mismatch");

      String data = "";
      for(int i = 0; i < keys.size(); i++)
      {
	 String pair = URLEncoder.encode((String)keys.get(i)) + "=" + URLEncoder.encode((String)values.get(i));
	 if(i + 1 < keys.size())
	    pair += "&";

	 data += pair;
      }

      this.data = data;
      return this.data;
   }
}
